Skip to content

Conversation

@zeapoz
Copy link
Contributor

@zeapoz zeapoz commented Aug 7, 2025

Currently shorthand field initializers are not captured the same way as the full initializers, leading to awkward and mismatching highlighting. This PR addresses this fact, in addition to capturing new highlights:

  • Tags the ! as part of a macro invocation.
  • Tags the identifier part of a lifetime as @lifetime.
  • Tag module definitions as a new capture group, @module.
  • Shorthand initializers are now properly tagged as @property.

Here's what the current version of Zed looks like:

image

With the new highlighting applied:

image

Release Notes:

  • Improved highlighting of Rust files, including new highlight groups for modules and shorthand initializers.

Currently shorthand field initializers are not captured the same way as
the full initializers leading to awkward and mismatching highlighting.

In addition, captures the `!` as part of a macro invocation.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Aug 7, 2025
@zeapoz zeapoz force-pushed the add-new-rust-highlight-capture-groups branch from 1bedb1d to 8896e87 Compare August 8, 2025 15:43
@zeapoz zeapoz changed the title Capture shorthand_field_initializer in rust highlights Capture shorthand_field_initializer and modules in rust highlights Aug 8, 2025
@maxdeviant maxdeviant changed the title Capture shorthand_field_initializer and modules in rust highlights Capture shorthand_field_initializer and modules in Rust highlights Aug 8, 2025
zeapoz added 2 commits August 9, 2025 18:11
This should rather be done in a separate PR as its a more sizable edit
Copy link
Collaborator

@probably-neb probably-neb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is an interesting change. I do have some reservations, primarily that these changes seem to be personal preferences, however, the impact would be universal. I'm not sure there's a way around that besides allowing customization of *.scm files by users. Additionally, if we do merge this, I definitely feel that we should remove the changes to imports. In my view, inconsistent highlighting is worse than consistent less semantic highlighting.

If you would please remove the import highlighting changes, and update the before and after screenshots to include examples of all changes I would be happy to review again

@zeapoz
Copy link
Contributor Author

zeapoz commented Aug 13, 2025

Thank you for the review @probably-neb! I agree that it would be beneficial for users to be able to specify their own capture groups in .scm files, Neovim comes to mind as it already supports this on a per-language basis with $NVIM_APPNAME/queries/<language>/highlights.scm

I think a good solution for the time being could be to allow users to have more granular highlighting options (while keeping the defaults sane). Currently, if something is not captured there is no way to replace the default highlighting, if something is, then there is the choice of either using the provided colored (i.e. from a color scheme) or overriding it themselves.

In any case, I've gone ahead and removed the use statement captures, and I also wrote up a quick Rust demo program to show off all the adjustments this PR makes. Hopefully this makes it clear of all the changes this time.

@probably-neb probably-neb enabled auto-merge (squash) August 22, 2025 19:57
@probably-neb probably-neb merged commit 896a35f into zed-industries:main Aug 22, 2025
21 checks passed
@zeapoz zeapoz deleted the add-new-rust-highlight-capture-groups branch August 23, 2025 06:17
orual pushed a commit to orual/zed that referenced this pull request Aug 23, 2025
…ed-industries#35842)

Currently shorthand field initializers are not captured the same way as
the full initializers, leading to awkward and mismatching highlighting.
This PR addresses this fact, in addition to capturing new highlights:
- Tags the `!` as part of a macro invocation.
- Tags the identifier part of a lifetime as `@lifetime`.
- Tag module definitions as a new capture group, `@module`.
- Shorthand initializers are now properly tagged as `@property`.

Here's what the current version of Zed looks like:

<img width="596" height="683" alt="image"
src="https://github.com/user-attachments/assets/c9e52d8e-03dc-426b-8545-4fe872b803e0"
/>

With the new highlighting applied:

<img width="596" height="683" alt="image"
src="https://github.com/user-attachments/assets/b7bd9391-9910-456b-8198-6871174d0f4f"
/>

Release Notes:

- Improved highlighting of Rust files, including new highlight groups
for modules and shorthand initializers.
maxdeviant added a commit that referenced this pull request Aug 25, 2025
maxdeviant added a commit that referenced this pull request Aug 25, 2025
…hlights (#35842)" (#36880)

This PR reverts #35842, as it
broke the syntax highlighting for `crate`:

### Before Revert

<img width="367" height="70" alt="Screenshot 2025-08-25 at 11 29 50 AM"
src="https://github.com/user-attachments/assets/ce9b8b59-4e89-43ed-84c7-95c0156b9168"
/>

### After Revert

<img width="353" height="69" alt="Screenshot 2025-08-25 at 11 32 17 AM"
src="https://github.com/user-attachments/assets/b6df5a21-64db-4abf-aa76-f085236da0c4"
/>

This reverts commit 896a35f.

Release Notes:

- Reverted #35842.
tidely pushed a commit to tidely/zed that referenced this pull request Sep 10, 2025
…ed-industries#35842)

Currently shorthand field initializers are not captured the same way as
the full initializers, leading to awkward and mismatching highlighting.
This PR addresses this fact, in addition to capturing new highlights:
- Tags the `!` as part of a macro invocation.
- Tags the identifier part of a lifetime as `@lifetime`.
- Tag module definitions as a new capture group, `@module`.
- Shorthand initializers are now properly tagged as `@property`.

Here's what the current version of Zed looks like:

<img width="596" height="683" alt="image"
src="https://github.com/user-attachments/assets/c9e52d8e-03dc-426b-8545-4fe872b803e0"
/>

With the new highlighting applied:

<img width="596" height="683" alt="image"
src="https://github.com/user-attachments/assets/b7bd9391-9910-456b-8198-6871174d0f4f"
/>

Release Notes:

- Improved highlighting of Rust files, including new highlight groups
for modules and shorthand initializers.
tidely pushed a commit to tidely/zed that referenced this pull request Sep 10, 2025
…hlights (zed-industries#35842)" (zed-industries#36880)

This PR reverts zed-industries#35842, as it
broke the syntax highlighting for `crate`:

### Before Revert

<img width="367" height="70" alt="Screenshot 2025-08-25 at 11 29 50 AM"
src="https://github.com/user-attachments/assets/ce9b8b59-4e89-43ed-84c7-95c0156b9168"
/>

### After Revert

<img width="353" height="69" alt="Screenshot 2025-08-25 at 11 32 17 AM"
src="https://github.com/user-attachments/assets/b6df5a21-64db-4abf-aa76-f085236da0c4"
/>

This reverts commit 896a35f.

Release Notes:

- Reverted zed-industries#35842.
FrGoIs pushed a commit to FrGoIs/zed that referenced this pull request Sep 29, 2025
…ed-industries#35842)

Currently shorthand field initializers are not captured the same way as
the full initializers, leading to awkward and mismatching highlighting.
This PR addresses this fact, in addition to capturing new highlights:
- Tags the `!` as part of a macro invocation.
- Tags the identifier part of a lifetime as `@lifetime`.
- Tag module definitions as a new capture group, `@module`.
- Shorthand initializers are now properly tagged as `@property`.

Here's what the current version of Zed looks like:

<img width="596" height="683" alt="image"
src="https://github.com/user-attachments/assets/c9e52d8e-03dc-426b-8545-4fe872b803e0"
/>

With the new highlighting applied:

<img width="596" height="683" alt="image"
src="https://github.com/user-attachments/assets/b7bd9391-9910-456b-8198-6871174d0f4f"
/>

Release Notes:

- Improved highlighting of Rust files, including new highlight groups
for modules and shorthand initializers.
FrGoIs pushed a commit to FrGoIs/zed that referenced this pull request Sep 29, 2025
…hlights (zed-industries#35842)" (zed-industries#36880)

This PR reverts zed-industries#35842, as it
broke the syntax highlighting for `crate`:

### Before Revert

<img width="367" height="70" alt="Screenshot 2025-08-25 at 11 29 50 AM"
src="https://github.com/user-attachments/assets/ce9b8b59-4e89-43ed-84c7-95c0156b9168"
/>

### After Revert

<img width="353" height="69" alt="Screenshot 2025-08-25 at 11 32 17 AM"
src="https://github.com/user-attachments/assets/b6df5a21-64db-4abf-aa76-f085236da0c4"
/>

This reverts commit 896a35f.

Release Notes:

- Reverted zed-industries#35842.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants